<?php

use Faker\Generator as Faker;
use App\Models\user;
use App\Models\Prize;
use App\Models\Filiale;

$factory->define(App\Models\PrizeRecord::class, function (Faker $faker) {
    $remark = $faker->sentence();
    // 随机取一个月以内的时间
    $updated_at = $faker->dateTimeThisMonth();
    // 传参为生成最大时间不超过，创建时间永远比更改时间要早
    $created_at = $faker->dateTimeThisMonth($updated_at);

    $user = User::all()->random();
    $prize = Prize::all()->random();
    $filiale = Filiale::all()->random();
    return [
        'prize_id' => $prize->id,
        'user_id' => $user->id,
        'filiale_id' => $filiale->id,
        'redeem_code' => str_random(15),
        'redeemflag' => $faker->randomElement($array = array (true,false)),
        'redeem_at' => $updated_at,
        'sendsmsflag' => $faker->randomElement($array = array (true,false)),
        'sendsms_at' => $created_at,
        'remark' => $remark,
        'created_at' => $created_at,
        'updated_at' => $updated_at,
    ];
});
